﻿///设置控制台的宽度和高度
int wide = 800, hight = 800;
Console.SetBufferSize(wide, hight);
/// 光标初始位置 
int x = 0, y = 0;
String direction = "";
Console.Write("Hello World");
///跳出条件
while (direction != "*")
{
    ///清除
    Console.Clear();
///不同方向处理
beforeswitch:
    switch (direction)
    {
        ///调节光标所在列与行
        case "S":
            if (y == hight)
            {
                Console.Write("重新输入一个方向");
                direction = Console.ReadKey().Key.ToString();
                Console.Clear();
                goto beforeswitch;
            }
            Console.SetCursorPosition(x, ++y); break;
        case "W":
            if (y == 0)
            {
                Console.Write("重新输入一个方向");
                direction = Console.ReadKey().Key.ToString();
                Console.Clear();
                goto beforeswitch;
            }
            Console.SetCursorPosition(x, --y); break;
        case "A":
            if (x == 0)
            {
                Console.Write("重新输入一个方向");
                direction = Console.ReadKey().Key.ToString();
                Console.Clear();
                goto beforeswitch;
            }
            Console.SetCursorPosition(--x, y); break;
        case "D":
            if (x == wide)
            {
                Console.Write("重新输入一个方向");
                direction = Console.ReadKey().Key.ToString();
                Console.Clear();
                goto beforeswitch;
            }
            Console.SetCursorPosition(++x, y); break;
    }
    ///再次显示
    Console.Write("Hello World");
    ///输入方向
    direction = Console.ReadKey().Key.ToString();
}
